﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPN.WebParts.Subscribe
{
    [ToolboxItemAttribute(false)]
    public class Subscribe : WebPart
    {
        #region Properties
        private string _Settings_WebUrl = "";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Settings")]
        [DisplayName("Web url")]
        public string Settings_WebUrl
        {
            get { return _Settings_WebUrl; }
            set { _Settings_WebUrl = value; }
        }

        private string _Label_HeaderTitle = "Newsletter";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Header title")]
        public string Label_HeaderTitle
        {
            get { return _Label_HeaderTitle; }
            set { _Label_HeaderTitle = value; }
        }

        private string _Label_SubscribeRadioButtonText = "Subscribe";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Subscribe radio button text")]
        public string Label_SubscribeRadioButtonText
        {
            get { return _Label_SubscribeRadioButtonText; }
            set { _Label_SubscribeRadioButtonText = value; }
        }

        private string _Label_UnSubscribeRadioButtonText = "UnSubscribe";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("UnSubscribe radio button text")]
        public string Label_UnSubscribeRadioButtonText
        {
            get { return _Label_UnSubscribeRadioButtonText; }
            set { _Label_UnSubscribeRadioButtonText = value; }
        }

        private string _Label_SubmitButton = "Submit";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Submit button text")]
        public string Label_SubmitButton
        {
            get { return _Label_SubmitButton; }
            set { _Label_SubmitButton = value; }
        }

        private string _Label_EmailText = "Enter your eMail address";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Email label text")]
        public string Label_EmailText
        {
            get { return _Label_EmailText; }
            set { _Label_EmailText = value; }
        }

        private string _Label_SubscribedText = "You have been successfully subscribed";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Subscribed message text")]
        public string Label_SubscribedText
        {
            get { return _Label_SubscribedText; }
            set { _Label_SubscribedText = value; }
        }

        private string _Label_AlreadySubscribedText = "Entered E-mail is already subscribed";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Already subscribed message text")]
        public string Label_AlreadySubscribedText
        {
            get { return _Label_AlreadySubscribedText; }
            set { _Label_AlreadySubscribedText = value; }
        }

        private string _Label_UnSubscribedText = "You have been successfully unsubscribed";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("UnSubscribed message text")]
        public string Label_UnSubscribedText
        {
            get { return _Label_UnSubscribedText; }
            set { _Label_UnSubscribedText = value; }
        }

        private string _Label_EmailNotValid = "Entered E-mail is not valid.";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [Category("SPN - Labels")]
        [DisplayName("Email Not Valid")]
        public string Label_EmailNotValid
        {
            get { return _Label_EmailNotValid; }
            set { _Label_EmailNotValid = value; }
        }
        #endregion
        
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SPN.WebParts/Subscribe/SubscribeUserControl.ascx";

        protected override void CreateChildControls()
        {
            SubscribeUserControl _uc = (SubscribeUserControl)Page.LoadControl(_ascxPath);
            _uc._Settings_WebUrl = _Settings_WebUrl;
            _uc._Label_AlreadySubscribedText = _Label_AlreadySubscribedText;
            _uc._Label_EmailNotValid = _Label_EmailNotValid;
            _uc._Label_EmailText = _Label_EmailText;
            _uc._Label_HeaderTitle = _Label_HeaderTitle;
            _uc._Label_SubmitButton = _Label_SubmitButton;
            _uc._Label_SubscribedText = _Label_SubscribedText;
            _uc._Label_SubscribeRadioButtonText = _Label_SubscribeRadioButtonText;
            _uc._Label_UnSubscribedText = _Label_UnSubscribedText;
            _uc._Label_UnSubscribeRadioButtonText = _Label_UnSubscribeRadioButtonText;
            Controls.Add(_uc);
        }
    }
}
